REFACTOR: Promote token-smuggling & misc converter defaults to ClassVar - #1967
Closed
Roman Lutz (romanlutz) wants to merge 1 commit into
Closed
Conversation
Hoist the shared ``action='encode'`` default for the SmugglerConverter family onto ``SmugglerConverter.DEFAULT_ACTION: ClassVar[Literal['encode', 'decode']]`` and switch the three subclasses (AsciiSmugglerConverter, SneakyBitsSmugglerConverter, VariationSelectorSmugglerConverter) to the sentinel-default pattern so they inherit the base's default without restating the literal. Also promote UnicodeSubstitutionConverter's ``start_value=0xE0000`` to ``DEFAULT_START_VALUE: ClassVar[int]`` via the same sentinel pattern. No value changes. No behaviour changes. Verified: ruff / ty / pytest tests/unit/prompt_converter/. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
Author
|
Closing per maintainer feedback on the constants-audit work. This PR introduced the sentinel-default pattern (changing Branch left intact in case any portion is worth cherry-picking later. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
REFACTOR: Promote token-smuggling & misc converter defaults to
ClassVarPart of the ongoing class-constants audit (see #1964, #1965). Pure structural rename — no value or behaviour changes.
What changed
Promotes hard-coded
__init__defaults onto the owning class asClassVarconstants, using the sentinel-default pattern documented in the audit kickoff so subclasses can inherit the default without restating it.pyrit/prompt_converter/token_smuggling/The four-class
SmugglerConverterfamily all sharedaction: Literal["encode", "decode"] = "encode". The default now lives once on the base:The three subclasses (
AsciiSmugglerConverter,SneakyBitsSmugglerConverter,VariationSelectorSmugglerConverter) now acceptaction: Literal["encode", "decode"] | None = Noneand delegate resolution to the base viasuper().__init__(action=action). Their existing_brick_legacy_init = Trueopt-out (positional-arg deprecation grandfathering, scheduled for removal in 0.16.0) is preserved unchanged.pyrit/prompt_converter/unicode_sub_converter.pyUnicodeSubstitutionConverterhad a lone hard-codedstart_value: int = 0xE0000. Promoted toDEFAULT_START_VALUE: ClassVar[int] = 0xE0000and the constructor uses the same sentinel pattern.Conventions followed
ClassVar[T]annotation on every promoted constant.X | None) for the sentinel parameter type.DEFAULT_*constant by name._brick_legacy_initand positional signatures preserved for the smuggler family (no signature changes).Verification
All green — 1012 passed, 38 skipped (no test changes needed; the public default is unchanged).